	$("#area").val('$!{obj.area}');
	$("#grade").val('$!{obj.grade}');

	var hanziReg= /^(([\u4e00-\u9fa5]{2,16})|([a-zA-Z]{2,16}))$/;
	var identityCardReg = /^(\d{6})(\d{4})(\d{2})(\d{2})(\d{3})([0-9]|X|x)$/;
	var parentPhoneReg= /^[1][0-9]{10}$/;
	
    var $name = $("#name");
	var $identityCard = $("#identityCard");
	var $school = $("#school");
	var $teacher = $("#teacher");
	var $parentName = $("#parentName");
	var $parentPhone = $("#parentPhone");
	
    var flagname = false;//公共flag 判断是不是验证通过
var flagidentityCard = false;//公共flag 判断是不是验证通过
var flagschool = false;//公共flag 判断是不是验证通过
var flagteacher = false;//公共flag 判断是不是验证通过
var flagparentName = false;//公共flag 判断是不是验证通过
var flagparentPhone = false;//公共flag 判断是不是验证通过

(function(){
	
    $("#confirmBtn").on("click", submit);

    //手机号输入框事件
    $name.on("onreadystatechange input blur", function(){
		var $this = $(this);
		var name = $.trim($this.val());

		flagname = validateForm($this, name, hanziReg, "请输入正确的姓名");
    });

    //手机号输入框事件
    $identityCard.on("onreadystatechange input blur", function(){
		var $this = $(this);
		var identityCard = $.trim($this.val());

		flagidentityCard = validateForm($this, identityCard, identityCardReg, "请输入正确的身份证号");
    });

	//手机号输入框事件
    $school.on("onreadystatechange input blur", function(){
		var $this = $(this);
		var school = $.trim($this.val());

		flagschool = validateForm($this, school, hanziReg, "请输入学校全名");
    });

    //手机号输入框事件
    $teacher.on("onreadystatechange input blur", function(){
		var $this = $(this);
		var teacher = $.trim($this.val());

		flagteacher = validateForm($this, teacher, hanziReg, "请输入老师全名");
    });

    //手机号输入框事件
    $parentName.on("onreadystatechange input blur", function(){
		var $this = $(this);
		var parentName = $.trim($this.val());

		flagparentName = validateForm($this, parentName, hanziReg, "请输入正确的父母名");
    });

    //手机号输入框事件
    $parentPhone.on("onreadystatechange input blur", function(){
		var $this = $(this);
		var parentPhone = $.trim($this.val());

		flagparentPhone = validateForm($this, parentPhone, parentPhoneReg, "请输入正确的父母电话");
    });

    //表单验证, 前面四个都是必传参数：当前输入框、当前值、正则、提示文字，最后一个参数是可选参数：查看明文密码
    function validateForm(that, value, reg, txt, cleartext){
		var $parent = that.closest(".form-group");
		var $addon = $parent.find(".input-group-addon");
		var $msg = $parent.find(".js-line-alert");
		var $msgText = $parent.find(".js-alert-text");

		var flag = true;

		if(value.length === 0){
		modifyWarning($msgText, txt);
		showWarning($addon, that, $msg, cleartext);
		flag = false;
		}
		else if(!reg.test(value)){
		modifyWarning($msgText, txt);
		showWarning($addon, that, $msg, cleartext);
		flag = false;
		}
		else{
		hideWarning($addon, that, $msg, cleartext);
		}

		return flag;
    }

    //输入框边框变红并显示提示文字
    function showWarning(addon, input, msg, cleartext){
        if(cleartext){
          cleartext.addClass("input-error border-error");
        }
        addon.addClass("border-error");
        input.addClass("input-error border-error");
        msg.show();
    }

    //输入框边框恢复原色并隐藏提示文字
    function hideWarning(addon, input, msg, cleartext){
        if(cleartext){
          cleartext.removeClass("input-error border-error");
        }
        addon.removeClass("border-error");
        input.removeClass("input-error border-error");
        msg.hide();
    }

    //修改提示文字信息
    function modifyWarning(element, txt){
        element.text(txt);
    }

	//表单登录提交
    function submit(){
		var name = $.trim($name.val());
		var identityCard = $.trim($identityCard.val());
		var school = $("#school").val();
		var area = $("#area").val();
		var grade = $("#grade").val();
		var teacher = $("#teacher").val();
		var parentName = $("#parentName").val();
		var parentPhone = $("#parentPhone").val();
		var orderId = $("#orderId").val();

    $name.blur();
    $identityCard.blur();
    $school.blur();
    $teacher.blur();
    $parentName.blur();
    $parentPhone.blur();

    if(flagname && flagidentityCard && flagschool && flagteacher && flagparentName && flagparentPhone){
			$.ajax({
            	url: "upForm",
            	type: "post",
            	dataType: 'json',
            	data : {
					orderId:orderId,
					name:name,
					identityCard:identityCard,
					school:school,
            		area:area,
            		grade:grade,
					teacher:teacher,
					parentName:parentName,
					parentPhone:parentPhone
            	},
            	success: function(data) {
            		if (data.returnFlag == '0') {
            			location.href = "dtFormPage?orderId="+orderId;
            		}else {
						if (data.returnCode == 'A001') {
                            layer.open({
                                content: '该身份证号已参加活动!',
                                scrollbar: false
                            });
						}else if (data.returnCode == 'A003') {
                            layer.open({
                                content: '已付款不能修改个人信息!',
                                scrollbar: false
                            });
						}else{
                            layer.open({
                                content: '验证失败!',
                                scrollbar: false
                            });
						}
						
            		}
            	},
            	error: function(xhr, type, errorThrown) {
            		//异常处理；
					validateFormShow("请稍后再试!")
            	}
			});
		}
    }

})();